package com.uzai.console.web.uzaichat;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.IdentityEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.profit.nuserrewardrulegroup.NuserRewardRuleGroupQuery;
import com.uzai.console.dto.uzaichat.kefutalk.KefuTalkIdDto;
import com.uzai.console.dto.uzaichat.kefutalk.KefuTalkIdListDto;
import com.uzai.console.dto.uzaichat.kefutalk.KefuTalkInfoDto;
import com.uzai.console.dto.uzaichat.kefutalk.KefuTalkQuery;
import com.uzai.console.dto.uzaichat.kefutalktype.KefuTalkTypeIdDto;
import com.uzai.console.dto.uzaichat.kefutalktype.KefuTalkTypeInfoDto;
import com.uzai.console.dto.uzaichat.kefutalktype.KefuTalkTypeQuery;
import com.uzai.console.entity.KefuTalk;
import com.uzai.console.entity.KefuTalkType;
import com.uzai.console.entity.NuserRewardRuleGroup;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.KefuTalkTypeMapper;
import com.uzai.console.service.uzaichat.KefuTalkService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.uzaichat.kefutalk.KefuTalkInfoVo;
import com.uzai.console.vo.uzaichat.kefutalktype.KefuTalkTypeInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuqi
 * @date 2021年08月25日 20:15
 */
@Api(value = "快捷短语",tags = "客服管理|快捷短语")
@ApiSort(20)
@RestController
public class KefuTalkContoller extends BaseController {
    private Logger logger = LoggerFactory.getLogger(KefuTalkContoller.class);

    @Autowired
    private KefuTalkService kefuTalkService;
    @Autowired
    private KefuTalkTypeMapper kefuTalkTypeMapper;

    @ApiOperation(value = "分页查询快捷短语列表", notes = "分页查询快捷短语列表", response = KefuTalkInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/kefuTalk/findKefuTalkList")
    public Object findKefuTalkList(@RequestBody KefuTalkQuery kefuTalkQuery){
        return kefuTalkService.findKefuTalkList(kefuTalkQuery);
    }

    @ApiOperation(value = "查询快捷短语详情", notes = "查询快捷短语详情", response = KefuTalkInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/kefuTalk/findKefuTalkInfo")
    public Object findKefuTalkInfo(@RequestBody KefuTalkIdDto kefuTalkIdDto){
        return kefuTalkService.findKefuTalkInfo(kefuTalkIdDto);
    }

    @ApiOperation(value = "添加快捷短语前检验接口", notes = "添加快捷短语前检验接口")
    @ApiOperationSupport(order = 3)
    @PostMapping("/kefuTalk/addKefuTalkUnit")
    public Object addKefuTalkUnit(){
        KefuTalkTypeQuery kefuTalkTypeQuery = new KefuTalkTypeQuery();
        kefuTalkTypeQuery.setMerId(getLoginInfo().getMerId());
        List<KefuTalkType> kefuTalkTypeList = kefuTalkTypeMapper.findByList(kefuTalkTypeQuery);
        if(kefuTalkTypeList == null || kefuTalkTypeList.size() == 0){
            throw  new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请先添加分类信息");
        }
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加快捷短语", notes = "添加快捷短语")
    @ApiOperationSupport(order = 3)
    @PostMapping("/kefuTalk/addKefuTalk")
    public Object addKefuTalk(@RequestBody KefuTalkInfoDto kefuTalkInfoDto){
        kefuTalkService.addKefuTalk(kefuTalkInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改快捷短语", notes = "修改快捷短语")
    @ApiOperationSupport(order = 4)
    @PostMapping("/kefuTalk/updateKefuTalk")
    public Object updateKefuTalk(@RequestBody KefuTalkInfoDto kefuTalkInfoDto){
        kefuTalkService.updateKefuTalk(kefuTalkInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除快捷短语", notes = "删除会员类m型")
    @ApiOperationSupport(order = 5)
    @PostMapping("/kefuTalk/deleteKefuTalk")
    public Object deleteKefuTalk(@RequestBody KefuTalkIdListDto kefuTalkIdListDto){
        kefuTalkService.deleteKefuTalk(kefuTalkIdListDto);
        return true;
    }

    @ApiOperation(value = "分页查询快捷短语分类列表", notes = "分页查询快捷短语分类列表", response = KefuTalkTypeInfoVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/kefuTalk/findKefuTalkTypeList")
    public Object findKefuTalkTypeList(@RequestBody KefuTalkTypeQuery kefuTalkTypeQuery){
        return kefuTalkService.findKefuTalkTypeList(kefuTalkTypeQuery);
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加快捷短语分类", notes = "添加快捷短语分类")
    @ApiOperationSupport(order = 7)
    @PostMapping("/kefuTalk/addKefuTalkType")
    public Object addKefuTalkType(@RequestBody KefuTalkTypeInfoDto kefuTalkTypeInfoDto){
        kefuTalkService.addKefuTalkType(kefuTalkTypeInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除快捷短语分类", notes = "删除快捷短语分类")
    @ApiOperationSupport(order = 8)
    @PostMapping("/kefuTalk/deleteKefuTalkType")
    public Object deleteKefuTalkType(@RequestBody KefuTalkTypeIdDto kefuTalkTypeIdDto){
        kefuTalkService.deleteKefuTalkType(kefuTalkTypeIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KefuTalk, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改快捷短语分类", notes = "修改快捷短语分类")
    @ApiOperationSupport(order = 9)
    @PostMapping("/kefuTalk/updateKefuTalkType")
    public Object updateKefuTalkType(@RequestBody KefuTalkTypeInfoDto kefuTalkTypeInfoDto){
        kefuTalkService.updateKefuTalkType(kefuTalkTypeInfoDto);
        return true;
    }

    @ApiOperation(value = "查询快捷分类下拉列表框", notes = "查询快捷短语分类下拉列表框", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/kefuTalk/findKefuTalkTypeSelect")
    public Object findKefuTalkTypeSelect(@RequestBody KefuTalkTypeQuery kefuTalkTypeQuery){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();
        Page<KefuTalkType> page = new Page<>();
        kefuTalkTypeQuery.convert(page);
        List<KefuTalkType> kefuTalkTypeList = kefuTalkTypeMapper.findByList(page, kefuTalkTypeQuery);
        if(kefuTalkTypeList != null && kefuTalkTypeList.size() > 0){
            for(KefuTalkType kefuTalkType : kefuTalkTypeList){
                SelectKeyVo selectKeyVo =  new SelectKeyVo();
                selectKeyVo.setKey(String.valueOf(kefuTalkType.getId()));
                selectKeyVo.setValue(kefuTalkType.getName());
                selectIdVoList.add(selectKeyVo);
            }
        }
        return selectIdVoList;
    }

}
